/**
 * Created by waltyuqing on 16/11/28.
 */
// <%--上传图片--%>
var img_url="";
function UpladFile(obj) {
    var objVal = $(obj).val();
    var name = objVal.split("\\")[2];
    var tail = name.split(".")[1];
    if(tail=="jpg"||tail=="png"||tail=="jpeg"){
        var fileObj = obj.files[0]; 						// js 获取文件对象
        var FileController = "http://cloud.eeesys.com/pu/upload.php";                    // 接收上传文件的后台地址
        // FormData 对象
        var form = new FormData();
        form.append("author", "hooyes");                    // 可以增加表单数据
        form.append("act", "file");                    // 可以增加表单数据
        form.append("file", fileObj);                       // 文件对象
        // XMLHttpRequest 对象
        var xhr = new XMLHttpRequest();
        xhr.open("post", FileController, true);
        xhr.onload = function (res) {
            var rr = JSON.parse(xhr.responseText);
            var timestamp = Date.parse(new Date()) + "";
            img_url=rr.url;
            //console.log(img_url);
        };
        console.log(img_url);
        xhr.send(form);
        return;
    }
    else{
        swal("只支持jpg和png的图片格式");
        return;
    }
}
//x下拉框
$('.par_choose_select').change(
    function(){
        $.ajax({
            type: 'post',
            url: "../api/message_manage/department/list_s_departments.jsp",
            data: {
                deptCode:$(this).attr("id"),
            },
            timeout: 3000,
            dataType: 'json',
            success:function (data) {
                $('.ch_choose_select').empty()
                if(data.errcode==0){
                    $('.ch_choose_select').show()
                    $('.ch_choose_select').append(
                        '<option value="-1">全部</option>'
                    )
                    for(var i=0;i<data.depts.length;i++){
                        $('.ch_choose_select').append(
                            '<option  value="'+data.depts[i].deptCode+'">'+data.depts[i].deptName+'</option>'
                        )
                    }
                }else{
                    $('.ch_choose_select').hide()
                }
            },
            error:function (error) {
                swal('添加二级失败修改失败')
            }
        });
        return false;//阻止提交
    }
)

//页面初始化颜色
localStorage.setItem('edit_dep_id',$('.first_subject .subject').eq(0).attr('id'));
$('.first_subject .subject').eq(0).addClass('sub_bg_color')
$('body').on('click','.second_subject .subject',
    function(){
        $(this).addClass('sub_bg_color').siblings().removeClass('sub_bg_color');
        localStorage.setItem('edit_dep_id',$(this).attr('id'));

    }
)
localStorage.setItem('parentid',$('.first_subject .subject').eq(0).attr('id'));
$('body').on('click','.first_subject .subject',
    function(){
        // parentid=$(this).attr('id')
        // alert($(this).attr('id'))

         $(this).addClass('sub_bg_color').siblings().removeClass('sub_bg_color');
         // parentid=$('.first_subject li.sub_bg_color').attr('id')
         // alert(parentid)

       localStorage.setItem('parentid',$(this).attr('id'));
       localStorage.setItem('edit_dep_id',$(this).attr('id'));
    }
)


//页面初始化
$(
    function(){
        //页面初始化一二级科室
        $.ajax({
            type: 'post',
            url: "/api/message_manage/department/list_s_departments.jsp",
            data: {
                deptCode:$('.first_subject .subject').eq(0).attr('id'),
            },
            timeout: 3000,
            dataType: 'json',
            success:function (data) {
                $('.second_subject').empty()
                if(data.errcode==0){
                    for(var i=0;i<data.depts.length;i++){
                        $('.second_subject').append(
                            '<li class="subject" id="'+data.depts[i].deptCode+'">'+data.depts[i].deptName+'<span class="delete_dep"><img src="../images/rubbish.png"></span></li>'
                        )
                    }
                    $('.second_subject').append(
                        ' <li class="add_second_subject">+添加二级科室</li>'
                    );
                    $('.first_subject li span,.second_subject li span').hide();
                    $('.first_subject li,.second_subject li').mouseenter(
                        function(){
                            $(this).find('span').show();
                        })
                    $('.first_subject li,.second_subject li').mouseleave(
                        function(){
                            $(this).find('span').hide();
                        }
                    );
                }else{
                    $('.second_subject').append(
                        ' <li class="add_second_subject">+添加二级科室</li>'
                    )
                    $('.ch_choose_select').hide()
                }
            },
            error:function (error) {
                swal('添加二级失败修改失败')
            }
        });
        //页面科室初始信息
        $.ajax({
            type: 'post',
            url: "messages_dep_mes.jsp",
            data: {
                deptCode:$('.first_subject .subject').eq(0).attr('id'),
                act:"show",
            },
            timeout: 3000,
            dataType: 'json',
            success:function (data) {
                if(data.errcode==0){
                    if(data.dept.img==undefined||data.dept.img==''||data.dept.img=='null'){
                        data.dept.img='../images/no_image.png';
                    };
                    if(data.dept.json.address==undefined ||data.dept.json.address==''||data.dept.json.address=='null'){
                        data.dept.json.address="暂无"};
                    if(data.dept.json.phone==undefined||data.dept.json.phone=='null'||data.dept.json.phone==''){
                        data.dept.json.phone="暂无"
                    };
                    if(data.dept.content=='null'||data.dept.content==''||data.dept.content=='underfined'){
                        data.dept.content="暂无"
                    };
                    $('.edit_department_con').empty();
                    $('.edit_department_con').append(
                        '<ul class="subject_detail">' +
                        '<span class="see_department_image">' +
                        '<span class="see_department_image_in">' +
                        '<img src="'+data.dept.img+'" alt="" >' +
                        '</span>' +
                        '</span>' +
                        '<input type="hidden" class="intro_id" value="'+data.dept.id+'">' +
                        '<li class="edit_department_li">科室名称:<span>'+data.dept.dept_name+'</span></li>'+
                        '<li class="edit_department_li ">科室编号:<span>'+data.dept.dept_id+'</span></li>'+
                        '<li class="edit_department_li">科室类型:<span>'+data.dept.type+'</span></li>'+
                        '<li class="edit_department_li">科室地址:<span>'+data.dept.json.address+'</span></li>'+
                        '<li class="edit_department_li">咨询电话:<span>'+data.dept.json.phone+'</span></li>'+
                        '<li>'+
                        '<a href="messages_dep_mes_news.jsp?deptCode='+data.dept.dept_id+'&deptName='+data.dept.dept_name+'"><button class="ui_btn">科室新闻管理</button></a>'+
                        '<button class="ui_btn link_detpts" data-toggle="modal" data-target="#myModal">关联挂号科室</button>'+
                        '</li>'+
                        '<div>'+
                        '<span>科室介绍</span>'+
                        '<p>'+data.dept.content+'</p>'+
                        '<button id="edit_department_message" class="edit_department_message" >编辑科室信息</button>'+
                        '</div>'+
                        '</ul>'
                    )
                }else{
                }
            },
            error:function (error) {
                swal('没有相关数据')
            }
        });
    }
)
//编辑科室信息
$('body').on('click','.to_second_subject',
    function(){
        $.ajax({
            type: 'post',
            url: "../api/message_manage/department/list_s_departments.jsp",
            data: {
                deptCode:$(this).attr('id'),
            },
            timeout: 3000,
            dataType: 'json',
            success:function (data) {
                $('.second_subject').empty()
                if(data.errcode==0){
                    for(var i=0;i<data.depts.length;i++){
                        $('.second_subject').append(
                            '<li class="subject" value="'+data.depts[i].deptCode+'" id="'+data.depts[i].deptCode+'">'+data.depts[i].deptName+'<span class="delete_dep"><img src="../images/rubbish.png"></span></li>'
                        );
                    };
                    $('.second_subject').append(
                        ' <li class="add_second_subject">+添加二级科室</li>'
                    );
                    $('.first_subject li span,.second_subject li span').hide();
                    $('.first_subject li,.second_subject li').mouseenter(
                        function(){
                            $(this).find('span').show();
                        });
                    $('.first_subject li,.second_subject li').mouseleave(
                        function(){
                            $(this).find('span').hide();
                        }
                    );
                }else{
                    $('.second_subject').append(
                        ' <li class="add_second_subject">+添加二级科室</li>'
                    )
                    $('.ch_choose_select').hide()
                    // swal('没有二级科室')
                }
            },
            error:function (error) {
                swal('添加二级失败修改失败')
            }
        });
    }
);

//展示科室信息
$('body').on('click','.subject',
    function(){
        $.ajax({
            type: 'post',
            url: "messages_dep_mes.jsp",
            data: {
                deptCode:$(this).attr('id'),
                act:"show",
            },
            timeout: 3000,
            dataType: 'json',
            success:function (data) {
                if(data.errcode==0){
                    if(data.dept.img==undefined||data.dept.img==''||data.dept.img=='null'){
                        data.dept.img='../images/no_image.png';
                    };
                    if(data.dept.json.address==undefined ||data.dept.json.address==''||data.dept.json.address=='null'){
                        data.dept.json.address="暂无"};
                    if(data.dept.json.phone==undefined||data.dept.json.phone=='null'||data.dept.json.phone==''){
                        data.dept.json.phone="暂无"
                    };
                    if(data.dept.content=='null'||data.dept.content==''||data.dept.content=='underfined'){
                        data.dept.content="暂无"
                    };
                    $('.edit_department_con').empty();
                    $('.edit_department_con').append(
                        '<ul class="subject_detail">'+
                        '<span class="see_department_image">' +
                        '<span class="see_department_image_in">' +
                        '<img src="'+data.dept.img+'" alt="" >' +
                        '</span>' +
                        '</span>' +
                        '<input type="hidden" class="intro_id" value="'+data.dept.id+'">' +
                        '<li class="edit_department_li">科室名称:<span>'+data.dept.dept_name+'</span></li>'+
                        '<li class="edit_department_li intro_dept_id">科室编号:<span>'+data.dept.dept_id+'</span></li>'+
                        '<li class="edit_department_li">科室类型:<span>'+data.dept.type+'</span></li>'+
                        '<li class="edit_department_li">科室地址:<span>'+data.dept.json.address+'</span></li>'+
                        '<li class="edit_department_li">咨询电话:<span>'+data.dept.json.phone+'</span></li>'+
                        '<li>'+
                        '<a href="messages_dep_mes_news.jsp?deptCode='+data.dept.dept_id+'&deptName='+data.dept.dept_name+'"><button class="ui_btn">科室新闻管理</button></a>'+
                        '<button class="ui_btn link_detpts" data-toggle="modal" data-target="#myModal">关联挂号科室</button>'+
                        '</li>'+
                        '<div>'+
                        '<span>科室介绍</span>'+
                        '<p>'+data.dept.content+'</p>'+
                        '<button id="edit_department_message">编辑科室信息</button>'+
                        '</div>'+
                        '</ul>'
                    )
                }else{
                    $('.edit_department_con').empty();
                    $('.edit_department_con').append(
                        '<li class="edit_department_li">没有相关数据</span></li>'
                    )
                    $('.ch_choose_select').hide()
                    swal('没有相关数据')
                }
            },
            error:function (error) {
                swal('添加二级失败修改失败')
            }
        });
    }
)
//编辑科室
$('body').on("click", "#edit_department_message",
    function () {
        $('.edit_department li p').hide();
        $.ajax({
            type: 'post',
            url: "messages_dep_mes.jsp",
            data: {
                deptCode:localStorage.getItem('edit_dep_id'),
                act:"show",
            },
            timeout: 3000,
            dataType: 'json',
            success:function (data) {

                if(data.errcode==0){
                    if(data.dept.img==undefined||data.dept.img==''||data.dept.img=='null'){
                        data.dept.img='../images/no_image.png';
                    };
                    if(data.dept.json.address==undefined ||data.dept.json.address==''||data.dept.json.address=='null'){
                        data.dept.json.address="暂无"};
                    if(data.dept.json.phone==undefined||data.dept.json.phone=='null'||data.dept.json.phone==''){
                        data.dept.json.phone="暂无"
                    };
                    if(data.dept.content=='null'||data.dept.content==''||data.dept.content=='underfined'){
                        data.dept.content="暂无"
                    };
                   $('.edit_department_con').empty();
                    $('.edit_department_con').append(
                        '<div class="edit_department">' +
                        '<span>点击图片上传科室新图片</span>'+
                        '<form action="messages_dep_mes.jsp" method="post" name="example" onsubmit="return checkEdit()">'+
                        '<input type="hidden" name="act" value="edit"/>'+
                        '<input type="hidden" name="head_image" value="'+data.dept.img+'"/>'+
                        '<input type="hidden" name="deptCode" value="'+data.dept.dept_id+'"/>'+
                        '<li class="edit_department_image">' +
                        '<span ><input type="file" type="text" onchange="UpladFile(this)"></span>' +
                        '<div class="edit_department_image_in">' +
                        '<img src="'+data.dept.img+'" alt="" >' +
                        '</div>' +
                        '</li>' +
                        '<div class="clearfix"></div>'+
                        '<li class="edit_department_li">科室编号：<span class="depar_number">'+data.dept.dept_id+'</span></li>'+
                        '<li class="edit_department_li">科室名称：<span><input type="text" name="deptName" value="'+data.dept.dept_name+'" class="depar_name"></span><p class="depar_name_tip" >请输入科室名称</p></li>'+
                        '<li class="edit_department_li">科室地址：<span><input type="text" name="address" value="'+data.dept.json.address+'" class="depar_address" placeholder="如: 门诊部三楼北区"></span><p class="depar_address_tip">请输入科室地址</p></li>'+
                        '<li class="edit_department_li">咨询电话：<span><input type="text" name="phone" value="'+data.dept.json.phone+'"  class="depar_tel" placeholder="填写科室或医院电话"></span><p class="depar_tel_tip">请输入科室电话</p></li>' +
                        '<li class="edit_department_li">科室介绍：<span class="intro_limit">(限输入2000个字，其中包含换行、空格及标点符号在内)</span></li>'+
                        '<textarea name="content" id="" cols="30" rows="10" maxlength="2000" class="depar_intro" style="width:100px;height:300px;visibility:hidden;">'+data.dept.content+'</textarea>'+
                        '<div class="message_save_giveup">'+
                        '<button class="message_giveup" id="edit_department_giveup">放弃</button>'+
                        '<input type="submit" class="message_save" id="edit_department_save" value="保存"/>'+
                        '</div>'+
                        '</form>'+
                        '</div>'
                    )
                    KindEditor.ready(function(K) {
                        var editor2 = K.create('textarea[name="content"]', {
                            cssPath : '../news/plugins/code/prettify.css',
                            uploadJson : '../news/jsp/upload_json.jsp',
                            fileManagerJson : '../news/jsp/file_manager_json.jsp',
                            allowFileManager : true,
                            afterCreate : function() {
                                var self = this;
                                K.ctrl(document, 13, function() {
                                    self.sync();
                                    document.forms['example'].submit();
                                });
                                K.ctrl(self.edit.doc, 13, function() {
                                    self.sync();
                                    document.forms['example'].submit();
                                });
                            }
                        });
                        prettyPrint();
                    });
                    $('.edit_department li p').hide();
                    //预览图片
                    $('.edit_department_image span input').change(function(e){
                        // <%--图片预览--%>
                        var file=e.target.files[0]
                        var img=new Image();
                        img.src=URL.createObjectURL(file);
                        var url=img.src;
                        var $img=$(img);
                        img.onload=function(){
                            URL.revokeObjectURL(url);
                            $('.edit_department_image_in').empty().append($img);
                        }
                    })
                }else{
                    swal('无法编辑')
                }
            },
            error:function (error) {
                swal('添加二级失败修改失败')
            }
        });
        //放弃编辑科室
        $('body').on('click','#edit_department_giveup',
            function () {
                $.ajax({
                    type: 'post',
                    url: "messages_dep_mes.jsp",
                    data: {
                        deptCode:localStorage.getItem('edit_dep_id'),
                        act:"show",
                    },
                    timeout: 3000,
                    dataType: 'json',
                    success:function (data) {

                        if(data.errcode==0){
                            if(data.dept.img==undefined||data.dept.img==''||data.dept.img=='null'){
                                data.dept.img='../images/no_image.png';
                            };
                            if(data.dept.json.address==undefined ||data.dept.json.address==''||data.dept.json.address=='null'){
                                data.dept.json.address="暂无"};
                            if(data.dept.json.phone==undefined||data.dept.json.phone=='null'||data.dept.json.phone==''){
                                data.dept.json.phone="暂无"
                            };
                            if(data.dept.content=='null'||data.dept.content==''||data.dept.content=='underfined'){
                                data.dept.content="暂无"
                            };
                            $('.edit_department_con').empty();
                            $('.edit_department_con').append(
                                '<ul class="subject_detail">'+
                                '<span class="see_department_image">' +
                                '<span class="see_department_image_in">' +
                                '<img src="'+data.dept.img+'" alt="" >' +
                                '</span>' +
                                '</span>' +
                                '<input type="hidden" class="intro_id" value="'+data.dept.id+'">' +
                                '<li class="edit_department_li">科室名称:<span>'+data.dept.dept_name+'</span></li>'+
                                '<li class="edit_department_li intro_dept_id">科室编号:<span>'+data.dept.dept_id+'</span></li>'+
                                '<li class="edit_department_li">科室类型:<span>'+data.dept.type+'</span></li>'+
                                '<li class="edit_department_li">科室地址:<span>'+data.dept.json.address+'</span></li>'+
                                '<li class="edit_department_li">咨询电话:<span>'+data.dept.json.phone+'</span></li>'+
                                '<li>'+
                                '<a href="messages_dep_mes_news.jsp?deptCode='+data.dept.dept_id+'&deptName='+data.dept.dept_name+'"><button class="ui_btn">科室新闻管理</button></a>'+
                                '<button class="ui_btn link_detpts">关联挂号科室</button>'+
                                '</li>'+
                                '<div>'+
                                '<span>科室介绍</span>'+
                                '<p>'+data.dept.content+'</p>'+
                                '<button id="edit_department_message">编辑科室信息</button>'+
                                '</div>'+
                                '</ul>'
                            )
                        }else{
                            $('.edit_department_con').empty();
                            $('.edit_department_con').append(
                                '<li class="edit_department_li">没有相关数据</span></li>'
                            )
                            $('.ch_choose_select').hide()
                            swal('没有相关数据')
                        }
                    },
                    error:function (error) {
                        // swal('未知错误')
                    }
                });
                //window.location.reload();
            }
        )
    }
)

//添加一级科室
$('body').on("click",".add_first_subject",
    function(){
        $('.edit_department_con').empty();
        $('.edit_department_con').append(
        '<div class="edit_department">'+
        '<form action="messages_dep_mes.jsp" method="post" name="example" onsubmit="return check()">'+
        '<input type="hidden" name="act" value="add"/>'+
        '<input type="hidden" name="type" value="1"/>'+
        '<input type="hidden" name="head_image" value=""/>'+
           '<li class="edit_department_image">' +
             '<span ><input type="file" type="text" onchange="UpladFile(this)"></span>' +
              '<div class="edit_department_image_in">' +
              '<img src="../images/dep_upload_image.jpg" alt="" >' +
             '</div>' +
            '</li>' +
            '<div class="clearfix"></div>'+
           '<li class="edit_department_li">科室名称：<span><input class="depar_name" name="deptName" type="text" placeholder="请输入一级科室名称"></span><p class="depar_name_tip">请输入一级科室名称</p></li>'+
            '<li class="edit_department_li">科室编号：<span><input class="depar_number" name="deptCode" type="text" placeholder="请输入科室编号"></span><p class="depar_number_tip">请输入科室编号</p></li>'+
            '<li class="edit_department_li">科室地址：<span><input class="depar_address" name="address" type="text" placeholder="如:门诊部三楼北区"></span><p class="depar_address_tip">请输入科室地址</p></li>'+
            '<li class="edit_department_li">咨询电话：<span><input class="depar_tel" name="phone" type="text" placeholder="填写科室或者电话,如:XXX"><p class="depar_tel_tip">请输入科室电话</p></span></li>'+
            '<li class="edit_department_li">科室介绍：<span class="intro_limit">(限输入2000个字，其中包含换行、空格及标点符号在内)</span></li>'+
            '<textarea name="content" id="" cols="30" rows="10" class="depar_intro" style="width:100px;height:300px;visibility:hidden;">'+
            '</textarea>'+
            '<div class="message_save_giveup">'+
            '<button class="message_giveup giveup_add_subject">放弃</button>'+
            '<input type="submit" class="message_save save_add_first_subject" value="保存" />'+
            '</div>'+
            '</form>'+
            '</div>'
        );
        KindEditor.ready(function(K) {
            var editor2 = K.create('textarea[name="content"]', {
                cssPath : '../news/plugins/code/prettify.css',
                uploadJson : '../news/jsp/upload_json.jsp',
                fileManagerJson : '../news/jsp/file_manager_json.jsp',
                allowFileManager : true,
                afterCreate : function() {
                    var self = this;
                    K.ctrl(document, 13, function() {
                        self.sync();
                        document.forms['example'].submit();
                    });
                    K.ctrl(self.edit.doc, 13, function() {
                        self.sync();
                        document.forms['example'].submit();
                    });
                }
            });
            prettyPrint();
        });
        //预览图片
        $('.edit_department_image span input').change(function(e){
            // <%--图片预览--%>
            var file=e.target.files[0]
            var img=new Image();
            img.src=URL.createObjectURL(file);
            var url=img.src;
            var $img=$(img);
            img.onload=function(){
                URL.revokeObjectURL(url);
                $('.edit_department_image_in').empty().append($img);
            }

        })
        $('.edit_department li p').hide();
        return false;
}
)

//添加二级
$('body').on("click", ".add_second_subject",
    function(){
        $('.edit_department_con').empty();
        $('.edit_department_con').append(
        '<div class="edit_department">'+
        '<form action="messages_dep_mes.jsp" method="post" name="example" onsubmit="return check()">'+
        '<input type="hidden" name="act" value="add"/>'+
        '<input type="hidden" name="parentId" value=""/>'+
        '<input type="hidden" name="type" value="2"/>'+
        '<input type="hidden" name="head_image" value=""/>'+
        '<li class="edit_department_image">' +
        '<span ><input type="file" type="text" onchange="UpladFile(this)"></span>' +
        '<div class="edit_department_image_in">' +
        '<img src="../images/dep_upload_image.jpg" alt="" >' +
        '</div>' +
        '</li>' +
            '<li class="edit_department_li">科室名称：<span><input type="text" class="depar_name" name="deptName" placeholder="请输入二级科室名称"></span> <p class="depar_name_tip" >请输入二级科室名称</p></li>'+
            '<li class="edit_department_li">科室编号：<span><input type="text"  class="depar_number" name="deptCode" placeholder="请输入科室编号"></span><p class="depar_number_tip">请输入科室编号</p></li>'+
            '<li class="edit_department_li">科室地址：<span><input type="text" class="depar_address" name="address" placeholder="如:门诊部三楼北区"></span><p class="depar_address_tip">请输入科室地址</p></li>'+
            '<li class="edit_department_li">咨询电话：<span><input type="text" class="depar_tel" name="phone" placeholder="填写科室或者电话,如:XXX"></span><p class="depar_tel_tip">请输入科室电话</p></li>'+
            '<li class="edit_department_li">科室介绍：<span class="intro_limit">(限输入2000个字，其中包含换行、空格及标点符号在内)</span></li>'+
            '<textarea name="content" style="width:100px;height:300px;visibility:hidden;" class="depar_intro"></textarea>'+
            '<div class="message_save_giveup">'+
            '<button class="message_giveup giveup_add_subject">放弃</button>'+
            '<input type="submit" class="message_save" value="保存" />'+
            '</div>'+
            '</form>'+
            '</div>'
        );
        KindEditor.ready(function(K) {
            var editor2 = K.create('textarea[name="content"]', {
                cssPath : '../news/plugins/code/prettify.css',
                uploadJson : '../news/jsp/upload_json.jsp',
                fileManagerJson : '../news/jsp/file_manager_json.jsp',
                allowFileManager : true,
                afterCreate : function() {
                    var self = this;
                    K.ctrl(document, 13, function() {
                        self.sync();
                        document.forms['example'].submit();
                    });
                    K.ctrl(self.edit.doc, 13, function() {
                        self.sync();
                        document.forms['example'].submit();
                    });
                }
            });
            prettyPrint();
        });

        $('.edit_department_image span input').change(function(e){
            // <%--图片预览--%>
            var file=e.target.files[0]
            var img=new Image();
            img.src=URL.createObjectURL(file);
            var url=img.src;
            var $img=$(img);
            img.onload=function(){
                URL.revokeObjectURL(url);
                $('.edit_department_image_in').empty().append($img);
            }
        })
        $('.edit_department li p').hide();
        //调用编辑器插件

    })
//放弃添加科室
$('body').on("click",".giveup_add_subject",
    function(){
        $('.edit_department_con').empty();
        $('.edit_department_con').append(
            '<div class="edit_department">' +
            '信息不存在!'+
            '</div>'
        )
        return false;
    }
)

//获取焦点失去焦点提示信息
  //科室名称
$('body').on('blur','.depar_name',
    function(){
        if($('.depar_name').val().trim()==""){
            $('.depar_name_tip').show();
            $('.depar_name').css("border","1px solid #ff0000")

        }
    }
)
$('body').on('focus','.depar_name',
    function(){
        if($('.depar_name').val().trim()==""){
            $('.depar_name_tip').hide();
            $('.depar_name').css("border","1px solid #d5d5d5")

        }
    }
)
  //科室地址
$('body').on('blur','.depar_address',
    function(){
        if($('.depar_address').val().trim()==""){
            $('.depar_address_tip').show();
            $('.depar_address').css("border","1px solid #ff0000")

        }
    }
)
$('body').on('focus','.depar_address',
    function(){
        if($('.depar_address').val().trim()==""){
            $('.depar_address_tip').hide();
            $('.depar_address').css("border","1px solid #d5d5d5")

        }
    }
)
  //科室电话
$('body').on('blur','.depar_tel',
    function(){
        if($('.depar_tel').val().trim()==""){
            $('.depar_tel_tip').show();
            $('.depar_tel').css("border","1px solid #ff0000")

        }
    }
)
$('body').on('focus','.depar_tel',
    function(){
        if($('.depar_tel').val().trim()==""){
            $('.depar_tel_tip').hide();
            $('.depar_tel').css("border","1px solid #d5d5d5")

        }
    }
)
   //科室编号
$('body').on('blur','.depar_number',
    function(){
        if($('.depar_number').val().trim()==""){
            $('.depar_number_tip').show();
            $('.depar_number').css("border","1px solid #ff0000")
        }
    }
)
$('body').on('focus','.depar_number',
    function(){
        if($('.depar_number').val().trim()==""){
            $('.depar_number_tip').hide();
            $('.depar_number').css("border","1px solid #d5d5d5")

        }
    }
)
   //科室渠道
$('body').on('blur','.depar_channel',
    function(){
        if($('.depar_channel').val().trim()==""){
            $('.depar_channel_tip').show();
            $('.depar_channel').css("border","1px solid #ff0000")

        }
    }
)
$('body').on('focus','.depar_channel',
    function(){
        if($('.depar_channel').val().trim()==""){
            $('.depar_channel_tip').hide();
            $('.depar_channel').css("border","1px solid #d5d5d5")

        }
    }
)
//删除科室
$('body').on('click','.delete_dep',
    function(){
        var deptCode=$(this).parent().attr('id');
        swal({
                title: "您确定要删除吗？",
                type: "warning",
                showCancelButton: true,
                closeOnConfirm: false,
                confirmButtonText: "是的，我要删除",
                 cancelButtonText:"取消",
                confirmButtonColor: "#ec6c62",
            },
            function(){
                $.ajax({
                    type: 'post',
                    url: "../api/message_manage/department/delete_department.jsp",
                    data: {
                        deptCode:deptCode,
                    },
                    timeout: 3000,
                    dataType: 'json',
                    success:function () {
                      window.location.reload();
                    },
                    error:function (error) {
                        swal('删除失败')
                    }
                });
                return false;//阻止提交
            }
        );

    }
)
function check(){

  if($('.depar_name').val().trim()==""){

    $('.depar_name_tip').show();
    $('.depar_name').css("border","1px solid #ff0000");
    return false;
  }else if($('.depar_number').val().trim()==""){

    $('.depar_number_tip').show();
    $('.depar_number').css("border","1px solid #ff0000");
    return false;
  }
  else if($('.depar_address').val().trim()==""){

    $('.depar_address_tip').show();
    $('.depar_address').css("border","1px solid #ff0000");
    return false;
  }else if($('.depar_tel').val().trim()==""){
    $('.depar_tel_tip').show();
    $('.depar_tel').css("border","1px solid #ff0000");
    return false;
  }
  if($(":hidden[name='type']").val()=='2'){
    $(":hidden[name='parentId']").val(localStorage.getItem('parentid'));
  }
  if(img_url!=""){
    $(":hidden[name='head_image']").val(img_url);
  }

  return true;
}
function checkEdit(){
    if($('.depar_name').val().trim()==""){

        $('.depar_name_tip').show();
        $('.depar_name').css("border","1px solid #ff0000");
        return false;
    }
    else if($('.depar_address').val().trim()==""){

        $('.depar_address_tip').show();
        $('.depar_address').css("border","1px solid #ff0000");
        return false;
    }else if($('.depar_tel').val().trim()==""){
        $('.depar_tel_tip').show();
        $('.depar_tel').css("border","1px solid #ff0000");
        return false;
    };
  if(img_url!=""){
    $(":hidden[name='head_image']").val(img_url);
  }
  return true;
}
